import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { JVxeTypes, JVxeColumn } from '/@/components/jeecg/JVxeTable/types';
import { getWeekMonthQuarterYear } from '/@/utils';
import { filterDictTextByCache, filterDictText } from '/@/utils/dict/JDictSelectUtil';
import { defHttp } from '/@/utils/http/axios';
import { h } from 'vue';
import { Avatar, Tag, Tooltip, Image } from 'ant-design-vue';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: 'id',
    align: 'center',
    dataIndex: 'id',
    width: 100,
  },
  {
    title: 'type',
    align: 'center',
    dataIndex: 'type',
    width: 100,
    ifShow: false
  },
  {
    title: '商品主图',
    align: 'center',
    dataIndex: 'mainPic',
    slots: { customRender: 'img' },
    //customRender: render.renderImage,
    width: 200,
  },
  {
    title: '商品描述',
    align: 'center',
    dataIndex: 'productName',
  },
  {
    title: '商品UPC条码',
    align: 'center',
    dataIndex: 'upcCode',
  },
  {
    title: '供价/元',
    align: 'left',
    dataIndex: 'supplyPrice',
    width: 150,
    edit: true,
    editRule: true,
    editComponent: 'InputNumber',
  },
];

async function renderTloadDictItem(dict: string, key: string) {
  let aa = key;
  await defHttp
    .get({
      url: `/sys/dict/loadDictItem/${dict}`,
      params: {
        key: key,
      },
    })
    .then((res) => {
      if (res && res.length > 0) {
        aa = res[0];
        console.log(aa);
      }
    });
  console.log('ttt' + aa);

  return 'aaa';
}

//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '商品UPC条码',
    field: 'upcCode',
    component: 'JInput', //TODO 范围查询
    //colProps: {span: 6},
  },
  {
    label: '商品描述',
    field: 'productName',
    component: 'JInput', //TODO 范围查询
    //colProps: {span: 6},
  },
];
//表单数据
export const ProductFormSchema: FormSchema[] = [
  {
    label: '商品编码',
    field: 'id',
    component: 'Input',
    dynamicDisabled: true,
    show: false,
  },
  {
    label: '商品UPC条码',
    field: 'upcCode',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入客户名称!' }];
    },
  },
  {
    label: '商品描述',
    field: 'productName',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入客户名称!' }];
    },
  },
  {
    label: '商品类目',
    field: 'productType',
    component: 'JTreeSelect',
    componentProps: {
      dict: 'xl_product_type,type_desc,id',
      pidField: 'pid',
      hasChildField: 'has_child',
      pidValue: '0',
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入客户名称!' }];
    },
  },
  {
    label: '商品状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'xl_product_status',
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入客户名称!' }];
    },
    ifShow: false,
    defaultValue: 1,
  },
  {
    label: '商品品牌',
    field: 'brand',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入客户名称!' }];
    },
  },

  {
    label: '箱规',
    field: 'cartonSpec',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入客户名称!' }];
    },
  },
  {
    label: '产品规格',
    field: 'productSpec',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入客户名称!' }];
    },
  },
  {
    label: '进货单价',
    field: 'purchasePrice',
    component: 'InputNumber',
    suffix: '元',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入价格!' }];
    },
  },
  {
    label: '一批供价',
    field: 'l1Price',
    component: 'InputNumber',
    suffix: '元',
    dynamicRules: ({ model, schema }) => {
      return [{ required: false, message: '请输入价格!' }];
    },
    colProps: { span: 48 },
  },
  {
    label: '二批供价',
    field: 'l2Price',
    component: 'InputNumber',
    suffix: '元',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入价格!' }];
    },
    componentProps: {
      size: '100',
    },
  },
  {
    label: '三批供价',
    field: 'l3Price',
    component: 'InputNumber',
    suffix: '元',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入价格!' }];
    },
  },
  {
    label: '商品主图',
    field: 'mainPic',
    component: 'JImageUpload',
    componentProps: {
      fileMax: 1,
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请上传商品主图!' }];
    },
  },
];
